package models

import (
	"time"

	"gorm.io/gorm"
)

type Article struct {
	ID        uint           `json:"id" gorm:"primaryKey"`
	Title     string         `json:"title" gorm:"size:255;not null"`
	Content   string         `json:"content" gorm:"type:text;not null"`
	AuthorID  uint           `json:"author_id" gorm:"not null;index"` // 外键字段，并创建索引
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
	DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
	// 关联关系
	Author   User      `json:"author,omitempty" gorm:"foreignKey:AuthorID;constraint:OnDelete:CASCADE;"`    // 属于哪个用户
	Comments []Comment `json:"comments,omitempty" gorm:"foreignKey:ArticleID;constraint:OnDelete:CASCADE;"` // 拥有的评论
}
